var e = require;
var t = module;
var o = exports;
var n,
    i =
        (this && this.__extends) ||
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({ __proto__: [] }
                    instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]);
                })(e, t);
        }),
            function (e, t) {
                n(e, t);

                function o() {
                    this.constructor = e;
                }
                e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o());
            }),
    r =
        (this && this.__decorate) ||
        function (e, t, o, n) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, o, n);
            else
                for (var c = e.length - 1; c >= 0; c--)
                    (i = e[c]) && (a = (r < 3 ? i(a) : r > 3 ? i(t, o, a) : i(t, o)) || a);
            return r > 3 && a && Object.defineProperty(t, o, a), a;
        };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = cc._decorator,
    c = a.ccclass,
    u = a.property,
    s =
        (a.menu,
            (function (e) {
                i(t, e);

                function t() {
                    var t = (null !== e && e.apply(this, arguments)) || this;
                    t.lable = null;
                    t.labTip = null;
                    t.rzlabel = null;
                    t.nextLoad = null;
                    t.scenesBundleName = "Scenes";
                    t.scenesName = "Game";
                    t.otherPath = ["AudioBundle", "Res3", "Res2", "Res"];
                    t.tipVersion = "载入中...";
                    t.proSp = null;
                    t.curIsPlay = !1;
                    t.allCount = 0;
                    t.curPlayindex = 0;
                    t.curProOverIndex = 0;
                    t.enterGame = !1;
                    t.loadTime = 1e3;
                    t.lastLoadingTime = 0;
                    return t;
                }
                t.prototype.onLoad = function () {
                    var e = this;
                    this.allCount = this.otherPath.length;
                    this.curProOverIndex = this.allCount;
                    this.curPlayindex = this.allCount;
                    this.rzlabel.string = GameCof.SoftnessLabel;
                    this.firstEnter();
                    FontCof.init();
                    this.scheduleOnce(function () {
                        var t = cc.Canvas.instance;
                        e.doAdaptive(t);
                        e.labTip.node.runAction(cc.repeatForever(cc.sequence([cc.fadeTo(0.4, 150), cc.fadeTo(0.2, 255)])));
                        e.scheduleOnce(function () {
                            e.showTipMode();
                        }, 1);
                        e.addLoadB(function () {
                            e.init();
                        });
                    });
                };
                t.prototype.doAdaptive = function (e) {
                    var t = cc.view.getDesignResolutionSize(),
                        o = t.width / t.height,
                        n = cc.view.getFrameSize(),
                        i = o >= n.width / n.height;
                    e.fitWidth = i;
                    e.fitHeight = !i;
                };
                t.prototype.updataPro = function () {
                    var e = this;
                    if (!this.curIsPlay && this.curProOverIndex != this.curPlayindex && this.curPlayindex > 0) {
                        this.curIsPlay = !0;
                        this.curPlayindex--;
                        cc.tween(this.proSp)
                            .to(
                                0.1, { progress: 1 - this.curPlayindex / this.allCount }, {
                                progress: function (t, o, n, i) {
                                    e.lable.string = Math.min(100, Math.floor(100 * e.proSp.progress) + 5) + "%";
                                    return t + (o - t) * i;
                                }
                            }
                            )
                            .call(function () {
                                e.curIsPlay = !1;
                                e.updataPro();
                            })
                            .start();
                    }
                };
                t.prototype.addLoadB = function (e) {
                    var t = this;
                    if (this.otherPath.length > 0) {
                        for (var o = [], n = 0; n < this.otherPath.length; n++) o.push(this.otherPath[n]);
                        this.otherPath.length = 0;
                        for (n = 0; n < o.length; n++)
                            cc.assetManager.loadBundle(o[n], function () {
                                t.curProOverIndex--;
                                t.updataPro();
                                0 == t.curProOverIndex &&
                                    t.scheduleOnce(function () {
                                        t.addLoadB(e);
                                    }, 0.01);
                            });
                    } else this.firstLoadRes(e);
                };
                t.prototype.firstLoadRes = function (e) {
                    var x = this;
                    cc.assetManager.loadBundle("Res", function (t, o) {
                        if (o) {
                            o.load("UI/catAnimal/cat", cc.SpriteAtlas);
                            o.load("UI/food/foodtps", cc.SpriteAtlas);
                            o.load("UI/equipment/equipmenttps", cc.SpriteAtlas);
                            o.load("UI/costume/costumetps", cc.SpriteAtlas);
                            o.load("Fab/scrollTipView", cc.Prefab, function () { });
                            // o.load("Panel/UIPrivacy", cc.Prefab, function() {
                            o.load("/Conf/levelData", cc.JsonAsset, function () {
                                o.load("/Conf/map001", cc.JsonAsset, function () {
                                    x.a = true;
                                    x.check(e);
                                    // o.load("UI/levelmap/levelmaptps", cc.JsonAsset, function () {
                                    //     e && e();
                                    // });
                                });
                            });
                            // });
                        } else {
                            x.a = true;
                            x.check(e);
                        }
                    });
                    cc.assetManager.loadBundle("Res2", function (t, b) {
                        if (b) b.load("UI/levelmap/levelmaptps1", cc.JsonAsset, function () {
                            x.b = true;
                            x.check(e);
                        });
                    });
                };
                t.prototype.check = function (e) {
                    if (this.a && this.b) e && e();
                }
                t.prototype.init = function () {
                    QLooperNode.init("Res");
                    this.lable.string = "100%";
                    this.enterGame = !0;
                    this.lastLoadingTime = Date.now();
                };
                t.prototype.update = function () {
                    var e = this;
                    if (this.enterGame && Date.now() - this.lastLoadingTime > this.loadTime) {
                        this.enterGame = !1;
                        this.scheduleOnce(function () {
                            e.nextLoad.active ?
                                e.scheduleOnce(function () {
                                    e.init();
                                }) :

                                (e.node.zIndex = 100,
                                    cc.director.loadScene("Game"));
                            // cc.assetManager.loadBundle(e.scenesBundleName, function (t, o) {
                            //     o &&
                            //         o.loadScene(e.scenesName, function (t, o) {
                            //             e.node.zIndex = 100;
                            //             cc.director.runScene(o);
                            //         });
                            // });
                        }, 0.2);
                    }
                };
                t.prototype.showTipMode = function () {
                    var e = this,
                        t = this.tipVersion;
                    if ("" != t) {
                        var o = 0,
                            n = function () {
                                if (o < t.length) {
                                    o++;
                                    e.labTip.string = t.substring(0, o);
                                    e.scheduleOnce(function () {
                                        n();
                                    }, 0.05);
                                }
                            };
                        n();
                    }
                };
                t.prototype.requestLoginData = function () { };
                t.prototype.firstEnter = function () {
                    var e = GameCof.getLastId(),
                        t = GameCof.accountPrefix + e,
                        o = "" + e,
                        n = GameCof.platname,
                        i = GameCof.version,
                        r =
                            GameCof.baseUrlV3 +
                            GameCof.baseLibPathV3 +
                            GameCof.pathPlatformLogin2 +
                            "?account=" +
                            t +
                            "&password=" +
                            o +
                            "&platform=" +
                            n +
                            "&version=" +
                            i +
                            "&devid=&type=1&channel=" +
                            GameCof.channel +
                            "&isclouds=0";
                    // this.requestJson(
                    //     r,
                    //     function (e) {
                    //         e.code;
                    //     },
                    //     this,
                    //     "POST",
                    //     function () {}
                    // );
                };
                t.prototype.requestJson = function (e, t, o, n, i, r, a) {
                    var c = this;
                    void 0 === n && (n = "GET");
                    void 0 === i && (i = null);
                    void 0 === r && (r = null);
                    void 0 === a && (a = "application/x-www-form-urlencoded");
                    var u = new XMLHttpRequest();
                    u.onreadystatechange = function () {
                        if (4 == u.readyState)
                            if (u.status >= 200 && u.status < 400) t && t.call(o, JSON.parse(u.responseText));
                            else {
                                i && i.call(o, u);
                                if (GameCof.gamecacheLoginType1Count > 0) {
                                    GameCof.gamecacheLoginType1Count--;
                                    c.scheduleOnce(function () {
                                        c.requestJson(e, t, o, n, i, r, a);
                                    }, 1);
                                }
                            }
                    };
                    u.open(n, e + "&instime=" + GameCof.gamecacheLoginType1Count, !0);
                    u.setRequestHeader("Content-type", a);
                    null == r ? u.send() : u.send(JSON.stringify(r));
                };
                r([u(cc.Label)], t.prototype, "lable", void 0);
                r([u(cc.Label)], t.prototype, "labTip", void 0);
                r([u(cc.Label)], t.prototype, "rzlabel", void 0);
                r([u(cc.Node)], t.prototype, "nextLoad", void 0);
                r([u(cc.ProgressBar)], t.prototype, "proSp", void 0);
                return r([c], t);
            })(cc.Component));
o.default = s;